package com.fzu.express.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fzu.express.entity.Outlet;
import com.fzu.express.entity.SysLog;
import com.fzu.express.mapper.SysLogMapper;
import com.fzu.express.service.SysLogService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.fzu.express.utils.PageVO;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author liliye
 * @since 2022-11-16
 */
@Service
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService {

    @Override
    public PageVO listLog(SysLog sysLog, Integer pageNum, Integer pageSize) {
        Page<SysLog> page = new Page<>();
        LambdaQueryWrapper<SysLog> wrapper = new LambdaQueryWrapper<>();
        wrapper.eq(sysLog.getUserId()!=null, SysLog::getUserId, sysLog.getUserId());
        wrapper.like(StringUtils.hasText(sysLog.getContent()), SysLog::getContent, sysLog.getContent());
        wrapper.orderByDesc(SysLog::getCreateTime);
        page.setCurrent(pageNum);
        page.setSize(pageSize);
        page(page, wrapper);
        return PageVO.convert(page);
    }
}
